package com.cn.common.consistenthash;

/**
 * 虚拟节点
 *
 * @param <T>
 */
public class VirtualNode<T extends Node> implements Node {

    T pyhsicalNode;
    int replicaIndex;

    public VirtualNode() {
    }

    public VirtualNode(T pyhsicalNode, int replicaIndex) {
        this.pyhsicalNode = pyhsicalNode;
        this.replicaIndex = replicaIndex;
    }

    @Override
    public String getKey() {
        return this.pyhsicalNode.getKey() + "-" + replicaIndex;
    }

    public T getPyhsicalNode() {
        return pyhsicalNode;
    }

    public int getReplicaIndex() {
        return replicaIndex;
    }

    @Override
    public String toString() {
        return "VirtualNode{" +
                "pyhsicalNode=" + pyhsicalNode +
                ", replicaIndex=" + replicaIndex +
                '}';
    }
}
